package com.hejjon.controller;

import com.hejjon.core.bean.ResponseResult;
import com.hejjon.core.controller.BaseController;
import com.hejjon.domain.dto.FeaturePublishInfoDTO;
import com.hejjon.domain.request.BusiFeaturePublishRequest;
import com.hejjon.domain.request.FeaturePublishCategoryRequest;
import com.hejjon.service.IBusiFeaturePublishService;
import com.hejjon.service.IFeaturePublishCategoryService;
import com.hejjon.service.IFeaturePublishRecordService;
import com.hejjon.service.ISysDatabaseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/feature/publish")
public class BusiFeaturePublishController extends BaseController {


    @Resource
    private ISysDatabaseService databaseService;


    @Resource
    private IFeaturePublishCategoryService featurePublishCategoryService;

    @Resource
    private IFeaturePublishRecordService featurePublishRecordService;

    @Resource
    private IBusiFeaturePublishService busiFeaturePublishService;


    @PostMapping("/addCategory")
    public ResponseResult addCategory(@RequestBody FeaturePublishCategoryRequest request) {
        boolean ret = featurePublishCategoryService.add(request);
        return toResult(ret, "新增分类成功");
    }


    @GetMapping("/removeCategory")
    public ResponseResult removeCategory(@RequestParam("id") String id) {

        return toResult(featurePublishCategoryService.removeById(id), "分类删除成功");
    }


    @PostMapping("/listCategoryTree")
    public ResponseResult listCategoryTree(@RequestBody FeaturePublishCategoryRequest request) {
        return success(featurePublishCategoryService.listCategoryTree(request));
    }

    @PostMapping("/saveFeaturePublishInfo")
    public ResponseResult saveFeaturePublishInfo(@RequestBody FeaturePublishInfoDTO publishInfoDTO) {
        return toResult(featurePublishRecordService.saveFeaturePublishInfo(publishInfoDTO), "保存特征发布记录成功");
    }


    @PostMapping("/listFeaturePublishInfo")
    public ResponseResult listFeaturePublishInfo(@RequestBody FeaturePublishInfoDTO publishInfoDTO) {
        return success(featurePublishRecordService.listFeaturePublishInfo(publishInfoDTO));
    }


    @PostMapping("/doPublish")
    public ResponseResult doPublish(@RequestBody BusiFeaturePublishRequest req) {
        return toResult(busiFeaturePublishService.publish(req), "特征发布成功");
    }

    @PostMapping("/removePublishRecord")
    public ResponseResult removePublishRecord(@RequestBody BusiFeaturePublishRequest req) {
        return toResult(featurePublishRecordService.removeRecord(req.getRecordId(), req.getDatabaseId()));
    }


    @GetMapping("/getFeaturePublishDetail")
    public ResponseResult getFeaturePublishDetail(@RequestParam String recordId) {
        return success(featurePublishRecordService.getFeaturePublishDetail(recordId));
    }





}

